<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Setting_m extends MY_Model
{

	function __construct ()
	{
		parent::__construct();
	}
    /**
     * @param $setting_key
     * @return mixed
     * 查询单条
     */
    public function get_setting_by_key($setting_key){
        $query = $this->db
            ->select('*')
            ->get_where('setting', array('k'=>$setting_key));
        return $query->row_array();
    }
    /**
     * @param $key
     * @param $data
     * @return bool
     * 修改积分信息
     */
    public function sava_setting($key,$data){

        $this->db->where('k',$key);
        $this->db->update('setting', $data);
        return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
    }

    /**
     * @param $data
     * @return bool
     * 新增积分
     */
    public function add_setting($data){

        $this->db->insert('setting',$data);
        if($this->db->affected_rows() > 0){
            return $this->db->insert_id();
        }else{
            return false;
        }
    }

    /**
     * @param $where
     * @return bool
     * 删除
     */
    public function delete_shop_users_by($where){
        $this->db->where($where)->delete('setting');
        return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
    }

    /**
     * 获取自定义变量
     * @return mixed
     */
    public function get_setting_by_type(){
        $this->db->select('*');
        $this->db->from('setting');
        $this->db->order_by('ord','asc');
        $query = $this->db->get();
        if($query->num_rows() > 0){
            return $query->result_array();
        }
    }

    public function is_exist_key($key){
        $this->db->select('*');
        $this->db->from('setting');
        $this->db->where('k',$key);
        $total=$this->db->count_all_results();
        return $total;
    }

}
